package cn.ostack.tools.plantuml.clazz;

import cn.ostack.tools.plantuml.clazz.util.FileUtil;

import javax.swing.filechooser.FileFilter;
import java.io.File;
import java.nio.charset.Charset;
import java.util.List;

public class Main {
    //   private static Logger log = LoggerFactory.getLogger("Main");
    public static void main(String[] args) {
        File lifeC = new File("D:\\PhpWorkSpace\\lifePortal");
        FileFilter filter = new FileFilter() {
            @Override
            public boolean accept(File file) {
                return file.getName().endsWith("php");
            }

            @Override
            public String getDescription() {
                return null;
            }
        };
        File[] phpFile = FileUtil.listAll(lifeC, filter);
        for (File file : phpFile) {
            List<String> lineInFile = FileUtil.readFileByLines(file.getAbsolutePath(), "GBK");
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < lineInFile.size(); i++) {
                String line= lineInFile.get(i);
                if (i!=0){
                    builder.append(System.lineSeparator());
                }
                if (line.contains("global $")) {
                    builder.append(line.replace(",", ";global "));
                } else {
                    builder.append(line);
                }
            }
            FileUtil.SaveFileAs(builder.toString(), Charset.forName("GBK"), file.getAbsolutePath());
            System.out.println("Finish deal:" + file.getAbsolutePath());
        }
//        log.info("PhpFiles:{}",phpFile);
    }
}
